package cn.gson.school.controller.xitong;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import cn.gson.school.dao.xitong.UserAddDao;
import cn.gson.school.entity.xitong.RoleEntity;
import cn.gson.school.entity.xitong.UserEntity;
import cn.gson.school.mappers.xitong.UserAddMapper;
import cn.gson.school.service.xitong.XtUserService;
import lombok.extern.log4j.Log4j;

@Log4j
@Controller
@RequestMapping("/useradd")
public class UserAddController {
	@Autowired
	private XtUserService useraddservice;

	@PostMapping("save")
	@ResponseBody
	public JSONObject sava(@Valid UserEntity user, BindingResult br, @RequestParam(name = "roleName") String roleName) {
		JSONObject obj = new JSONObject();
		obj.put("success", false);
		if (br.hasErrors()) {
			obj.put("message", "校验失败！");
			obj.put("erros", br.getFieldErrors());

		}
		RoleEntity role=new RoleEntity();
		Long roleId= useraddservice.findUserId(roleName);
		role.setRoleId(roleId);
		
		return obj;
	}
}
